package com.yc.c110s2plyqnzf.util;

import org.springframework.core.convert.converter.Converter;

import java.time.LocalDate;

public class DateConvertor implements Converter<String, LocalDate> {
    // yyyy-mm-dd
    @Override
    public LocalDate convert(String source) {
        final String[] split = source.split("\\D+");
        try {
            int year = Integer.parseInt(split[0]);
            int month = Integer.parseInt(split[1]);
            int day = Integer.parseInt(split[2]);
            return LocalDate.of(year, month, day);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
